package com.fs.alert.utils;

import com.fs.api.enumeration.AlertType;
import com.fs.api.enumeration.EmergencyLevel;

import java.util.*;

public class AlertDescriptionGenerator {
    private static final Random RANDOM = new Random();

    // 现场环境特征词库
    private static final Map<AlertType, Map<EmergencyLevel, List<String>>> ENVIRONMENT_DESC = new HashMap<>() {{
        put(AlertType.BUILDING_FIRE, new HashMap<>() {{
            put(EmergencyLevel.URGENT, List.of("浓烟弥漫，能见度极低", "高温炙烤，结构坍塌", "火势猛烈，烟雾毒性强"));
            put(EmergencyLevel.WARNING, List.of("烟雾较浓，通风不良", "局部高温，火势可控", "烟尘弥漫，视线受阻"));
            put(EmergencyLevel.ALERT, List.of("轻微烟雾，空气尚可", "局部起火，温度正常", "烟气轻微，能见度良好"));
        }});
        put(AlertType.VEHICLE_FIRE, new HashMap<>() {{
            put(EmergencyLevel.URGENT, List.of("油箱爆炸，火势失控", "燃烧剧烈，浓烟滚滚", "高温熔化，碎片飞溅"));
            put(EmergencyLevel.WARNING, List.of("局部燃烧，烟雾扩散", "油渍起火，火势中等", "烟气浓重，车辆受损"));
            put(EmergencyLevel.ALERT, List.of("轻微冒烟，火苗可控", "局部过热，烟雾轻微", "起火点小，尚未扩散"));
        }});
        put(AlertType.CHEMICAL_FIRE, new HashMap<>() {{
            put(EmergencyLevel.URGENT, List.of("化学烟雾弥漫，毒性极高", "爆炸高温，气味刺鼻", "火光冲天，污染严重"));
            put(EmergencyLevel.WARNING, List.of("化学气味浓烈，烟雾扩散", "局部高温，毒气泄漏", "烟雾有毒，环境恶劣"));
            put(EmergencyLevel.ALERT, List.of("轻微化学气味，烟雾可控", "局部起火，气味较轻", "烟气微量，尚未扩散"));
        }});
        put(AlertType.FOREST_FIRE, new HashMap<>() {{
            put(EmergencyLevel.URGENT, List.of("烈焰冲天，林木尽毁", "浓烟蔽日，风助火势", "高温干燥，火场失控"));
            put(EmergencyLevel.WARNING, List.of("烟雾弥漫，火势蔓延", "局部燃烧，风向不定", "高温烟尘，林木受损"));
            put(EmergencyLevel.ALERT, List.of("轻微烟雾，火势初起", "局部起火，尚未扩散", "烟气稀薄，林木未燃"));
        }});
    }};

    // 危险物品信息词库
    private static final Map<AlertType, Map<EmergencyLevel, List<String>>> DANGEROUS_GOODS = new HashMap<>() {{
        put(AlertType.BUILDING_FIRE, new HashMap<>() {{
            put(EmergencyLevel.URGENT, List.of("燃气罐爆炸风险", "化学清洁剂大量燃烧", "易燃家具堆积"));
            put(EmergencyLevel.WARNING, List.of("少量易燃涂料", "燃气管道泄漏", "木质结构助燃"));
            put(EmergencyLevel.ALERT, List.of("少量纸张堆积", "小型电器短路", "轻微易燃垃圾"));
        }});
        put(AlertType.VEHICLE_FIRE, new HashMap<>() {{
            put(EmergencyLevel.URGENT, List.of("油箱燃料爆炸", "电池高温熔毁", "载有化学品燃烧"));
            put(EmergencyLevel.WARNING, List.of("少量燃油泄漏", "轮胎高温燃烧", "车载易燃货物"));
            put(EmergencyLevel.ALERT, List.of("少量机油起火", "电线短路冒烟", "小型燃料泄漏"));
        }});
        put(AlertType.CHEMICAL_FIRE, new HashMap<>() {{
            put(EmergencyLevel.URGENT, List.of("大量酸性化学品泄漏", "易爆气体罐燃烧", "剧毒物质挥发"));
            put(EmergencyLevel.WARNING, List.of("少量化肥燃烧", "化学溶剂泄漏", "有毒液体起火"));
            put(EmergencyLevel.ALERT, List.of("微量化学废料", "少量溶剂挥发", "轻微腐蚀性物质"));
        }});
        put(AlertType.FOREST_FIRE, new HashMap<>() {{
            put(EmergencyLevel.URGENT, List.of("干枯树脂助燃", "大片易燃灌木", "风吹易燃落叶"));
            put(EmergencyLevel.WARNING, List.of("少量干草堆积", "局部干燥树枝", "小型易燃植被"));
            put(EmergencyLevel.ALERT, List.of("少量枯叶起火", "微量干草燃烧", "小型植被冒烟"));
        }});
    }};

    // 事故描述词库
    private static final Map<AlertType, Map<EmergencyLevel, List<String>>> INCIDENT_DESC = new HashMap<>() {{
        put(AlertType.BUILDING_FIRE, new HashMap<>() {{
            put(EmergencyLevel.URGENT, List.of("多层建筑全面起火，人员被困", "火势失控，蔓延至邻近楼层", "爆炸引发大范围火灾"));
            put(EmergencyLevel.WARNING, List.of("厨房起火，火势扩散中", "电器故障引发局部火灾", "客厅燃烧，烟雾浓重"));
            put(EmergencyLevel.ALERT, List.of("窗帘起火，尚未扩散", "插座短路引发小火", "垃圾桶轻微燃烧"));
        }});
        put(AlertType.VEHICLE_FIRE, new HashMap<>() {{
            put(EmergencyLevel.URGENT, List.of("货车油箱爆炸，火势猛烈", "轿车全面燃烧，道路堵塞", "公交车起火，乘客逃生"));
            put(EmergencyLevel.WARNING, List.of("引擎舱起火，烟雾扩散", "轮胎燃烧，火势中等", "车内物品引发的局部火情"));
            put(EmergencyLevel.ALERT, List.of("车灯短路冒烟", "座椅轻微起火", "引擎盖下小范围火苗"));
        }});
        put(AlertType.CHEMICAL_FIRE, new HashMap<>() {{
            put(EmergencyLevel.URGENT, List.of("化工厂爆炸，毒气扩散", "储罐起火，火势失控", "化学品泄漏引发连环火灾"));
            put(EmergencyLevel.WARNING, List.of("实验室起火，化学品燃烧", "仓库局部火情，烟雾有毒", "生产线上突发火情"));
            put(EmergencyLevel.ALERT, List.of("实验设备冒烟，火势可控", "化学试剂轻微起火", "废料堆积引发小火"));
        }});
        put(AlertType.FOREST_FIRE, new HashMap<>() {{
            put(EmergencyLevel.URGENT, List.of("山林大火，火线超10公里", "风助火势，树冠层燃烧", "多点起火，全面失控"));
            put(EmergencyLevel.WARNING, List.of("灌木丛起火，蔓延中", "林间小火，烟雾扩散", "局部火情，风向加剧"));
            put(EmergencyLevel.ALERT, List.of("枯草起火，尚未蔓延", "小片林木冒烟", "林边轻微火情"));
        }});
    }};

    public static String generateEnvironmentDesc(AlertType type, EmergencyLevel level) {
        List<String> options = ENVIRONMENT_DESC.get(type).get(level);
        return options.get(RANDOM.nextInt(options.size()));
    }

    public static String generateDangerousGoods(AlertType type, EmergencyLevel level) {
        List<String> options = DANGEROUS_GOODS.get(type).get(level);
        return options.get(RANDOM.nextInt(options.size()));
    }

    public static String generateIncidentDesc(AlertType type, EmergencyLevel level) {
        List<String> options = INCIDENT_DESC.get(type).get(level);
        return options.get(RANDOM.nextInt(options.size()));
    }
}